package com.wl.myscalajob


case class UserInfo(userName:String,location:String,startTime:Int,duration:Int)

object Job3 {
  //UserA,LocationA,8,60
  //UserA,LocationA,9,60
  //UserB,LocationB,10,60
  //UserB,LocationB,11,80
  def main(args: Array[String]): Unit = {
    val infoes = List(
      UserInfo("UserA", "LocationA", 8, 60),
      UserInfo("UserA", "LocationA", 9, 60),
      UserInfo("UserB", "LocationB", 10, 60),
      UserInfo("UserB", "LocationB", 11, 60)
    )

    val userMap: Map[String, List[UserInfo]] = infoes.groupBy(t => t.userName + "," + t.location)

    val userSort: Map[String, List[UserInfo]] = userMap.mapValues(t => t.sortBy(f => f.startTime))

    var firstTime = 0

    val totalMap: Map[String, Int] = userSort.mapValues(f => {
      firstTime = f.head.startTime
      val sum = f.map(x => x.duration).sum
      sum
    })

    totalMap.foreach{
      case (datas,sumTimes) => println(s"$datas,$firstTime,$sumTimes")
    }
  }
}
